// const model = require('../mongoseDb/model')
const AsyncMysqljs = require('../mysql/index')
const Query = AsyncMysqljs().query


module.exports = async (ctx, next) => {
    let {id, type, is_show, name, create_time, pic_url, down_url, desc, thunder_url, baidu_url, baidu_password} = ctx.request.body;
    if(!name) {
        errorMsg(ctx, 'name 不能为空！')
        return
    }
    if(!pic_url) {
        errorMsg(ctx, 'pic_url 不能为空！')
        return
    }
    if(!down_url) down_url = ''
    if(!baidu_url) baidu_url = ''
    if(!baidu_password) baidu_password = ''


    const sql = 'UPDATE film SET type=?, is_show=?, name=?, pic_url=?, down_url=?, desc_txt=?, baidu_url=?, baidu_password=? WHERE id=?'
    try {
        const res = await Query(sql, [type, is_show, name, pic_url, down_url, desc, baidu_url, baidu_password, id])
    } catch (error) {
        errorMsg(ctx, error)
        return
    }
    ctx.body = {
        code: 1,
        data: {},
        msg: 'ok'
    }
}


const errorMsg = (ctx, msg) => {
    ctx.body = {
        code: 0,
        data: {},
        msg: msg
    }
}